const KoaRouter = require('koa-router')
// const renewalRouter = require('./renewal')
// const counterRouter = require('./counter')
// const deviceRouter = require('./device')
// const handoverRouter = require('./handover')
// const loginRouter = require('./login')
// const storeRouter = require('./store')
// const userRouter = require('./user')
// const categoryRouter = require('./category.js')
// const departmentRouter = require('./department.js')
// const partPurchaseRouter = require('./partPurchase.js')
// const partStoreRouter = require('./partStore.js')
// const partRouter = require('./part.js')

const router = new KoaRouter({
    prefix: '/api'
})

const fs = require('fs')
const path = require('path')
const basename = path.basename(__filename)

fs.readdirSync(__dirname)
    .filter(file => {
        return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'
    })
    .forEach(file => {
        router.use(require(path.join(__dirname, file)).routes())
    })

// router.use(loginRouter.routes())
// router.use(counterRouter.routes())
// router.use(deviceRouter.routes())
// router.use(handoverRouter.routes())
// router.use(storeRouter.routes())
// router.use(userRouter.routes())
// router.use(renewalRouter.routes())
// router.use(categoryRouter.routes())
// router.use(departmentRouter.routes())
// router.use(partPurchaseRouter.routes())
// router.use(partRouter.routes())
// router.use(partStoreRouter.routes())

// router.use('/common/:source', async (ctx, next) => {
//     ctx.Model = require(`../schema/${ctx.params.source}`).default
//     await next()
// }, commonRouter.routes())

module.exports = router
